#include "input.h"
/*
 * 功能: 检测键盘输入
 * 参数: 无
 * 返回: 无
 */
void detect_keyboard_input()
{
    // 获取当前按下的键
    int key = wb_keyboard_get_key();
    char key_display[50]; // 增大数组大小，避免溢出

    if (key != -1)
    { // 如果有键被按下
        switch (key)
        {
        case 'Q':
            strcpy(key_display, "Key Q pressed");
            break;
        case 'W':
            strcpy(key_display, "Key W pressed");
            break;
        case 'E':
            strcpy(key_display, "Key E pressed");
            break;
        case 'A':
            strcpy(key_display, "Key A pressed");
            break;
        case 'S':
            strcpy(key_display, "Key S pressed");
            break;
        case 'D':
            strcpy(key_display, "Key D pressed");
            break;
        case ' ':
            break;
        }

        // 显示标签
        wb_supervisor_set_label(
            0,           // 标签 ID
            key_display, // 显示内容
            0.01, 0.01,  // 标签位置 (x, y)
            0.1,         // 字体大小
            0x000000,    // 黑色文本
            0.0,         // 不透明
            "Arial"      // 字体
        );
    }
}

joystick_input joystick_input_1;
void detect_joystick_input()
{

    joystick_input_1.axis_y1 = wb_joystick_get_axis_value(0);
    joystick_input_1.axis_x1 = wb_joystick_get_axis_value(1);
    joystick_input_1.axis_y2 = wb_joystick_get_axis_value(2);
    joystick_input_1.axis_x2 = wb_joystick_get_axis_value(3);
    joystick_input_1.lt = wb_joystick_get_axis_value(4);
    joystick_input_1.rt = wb_joystick_get_axis_value(5);
    joystick_input_1.pov = wb_joystick_get_pov_value(0);

    switch (wb_joystick_get_pressed_button())
    {
    case -1: // 未按下按钮
        break;
    case 2:
        joystick_input_1.button_c = 1;
        break;
    case 3:
        joystick_input_1.button_z = 1;
        break;
    case 4:
        joystick_input_1.button_lb = 1;
        break;
    case 5:
        joystick_input_1.button_rb = 1;
        break;
    case 8:
        joystick_input_1.button_a = 1;
        break;
    case 9:
        joystick_input_1.button_b = 1;
        break;
    case 10:
        joystick_input_1.button_x = 1;
        break;
    case 11:
        joystick_input_1.button_y = 1;
        break;
    }
}